package com.example.demo.action;


import com.example.demo.dao.*;
import com.example.demo.model.Gonggao;
import com.example.demo.model.Ren;
import com.example.demo.model.User;
import com.example.demo.model.Zhuti;
import com.example.demo.util.Pager;
import com.example.demo.util.Util;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

@Controller
public class ManageAction extends ActionSupport {

	private static final long serialVersionUID = -4304509122548259589L;


	private String url = "./";

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	//获取请求对象
	public HttpServletRequest getRequest(){
		HttpServletRequest request = ServletActionContext.getRequest();
		return request;
	}
	
	
	//获取响应对象
	public HttpServletResponse getResponse(){
		HttpServletResponse response = ServletActionContext.getResponse();
		return response;
	}
	
	//获取session对象
	public HttpSession getSession(){
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		return session;
	}
	
	
	//获取输出对象
	public PrintWriter getPrintWriter() {
		
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");response.setContentType("text/html; charset=utf-8");
		PrintWriter writer = null;
		try {
			writer = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return writer;
	}
	

	@Autowired
	private UserDao userDao;
	
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
//登入请求
	public String login() throws IOException {
		HttpServletRequest request = this.getRequest();
		
		PrintWriter writer = this.getPrintWriter();
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		User user = userDao.selectBean(" where username = '" + username
				+ "' and password= '" + password + "' and role=0 and deletestatus=0 ");
		if (user != null) {
			HttpSession session = request.getSession();
			session.setAttribute("user", user);
			this.setUrl("admin/index.jsp");
			return "redirect";
		} else {
			writer.print("<script language=javascript>alert('用户名或者密码错误');window.location.href='adminlogin.jsp';</script>");
		}
		return null;
	}
	
//用户退出
	public String loginout() {
		HttpServletRequest request = this.getRequest();
		HttpSession session = request.getSession();
		session.removeAttribute("user");
		this.setUrl("adminlogin.jsp");
		return SUCCESS;
	}
	
//跳转到修改密码页面
	public String changepwd() {
		HttpServletRequest request = this.getRequest();
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		this.setUrl("admin/password.jsp");
		return SUCCESS;
	}
	
//修改密码操作
	public void changepwd2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		HttpSession session = request.getSession();
		User u = (User)session.getAttribute("user");
		String password1 = request.getParameter("password1");
		String password2 = request.getParameter("password2");
		User bean = userDao.selectBean(" where username= '"+u.getUsername()+"' and password= '"+password1+"' and deletestatus=0");
		String menu = request.getParameter("menu");
		if(bean!=null){
			bean.setPassword(password2);
			userDao.updateBean(bean);
			writer.print(
							"<script language=javascript>alert('修改成功');window.location.href='method!changepwd?menu="+menu+"';</script>");
		}else{
			writer.print(
							"<script language=javascript>alert('原密码错误');window.location.href='method!changepwd?menu="+menu+"';</script>");
		}
	}


	@Autowired
	private GonggaoDao gonggaoDao;

	
	public GonggaoDao getGonggaoDao() {
		return gonggaoDao;
	}

	public void setGonggaoDao(GonggaoDao gonggaoDao) {
		this.gonggaoDao = gonggaoDao;
	}
	
	
	

	//通知公告列表
	public String gonggaolist() {
		HttpServletRequest request = this.getRequest();
		//控制左边菜单栏的展示或者闭合
		String menu = request.getParameter("menu");

		request.setAttribute("menu",menu );
		
		String gtitle = request.getParameter("gtitle");
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		
		if (gtitle != null && !"".equals(gtitle)) {

			sb.append("gtitle like '%" + gtitle + "%'");
			sb.append(" and ");
			request.setAttribute("gtitle", gtitle);
		}
		
		
		
		sb.append("   deletestatus=0   order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = gonggaoDao.selectBeanCount(where.replaceAll("order by id desc", ""));
		request.setAttribute("list", gonggaoDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!gonggaolist?menu="+menu, "共有" + total + "条记录"));
		request.setAttribute("url", "method!gonggaolist?menu="+menu);
		request.setAttribute("url2", "method!gonggao");
		request.setAttribute("title", "通知公告管理");
		this.setUrl("admin/gonggao/gonggaolist.jsp");
		return SUCCESS;

	}
	
//跳转到添加通知公告页面
	public String gonggaoadd() {
		HttpServletRequest request = this.getRequest();
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		
		
		request.setAttribute("url", "method!gonggaoadd2?menu="+menu);
		request.setAttribute("title", "添加通知公告");
		this.setUrl("admin/gonggao/gonggaoadd.jsp");
		return SUCCESS;
	}
	

	
	

	//添加通知公告操作
	public void gonggaoadd2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		
		
		String gtitle = request.getParameter("gtitle");
		String gcontent = request.getParameter("gcontent");
				
		Gonggao bean =  new Gonggao();
		
		
		bean.setCtime(Util.getRiqi());
		
		bean.setGtitle(gtitle);
		bean.setGcontent(gcontent);
		
		
		
		
		gonggaoDao.insertBean(bean);
		
		String menu = request.getParameter("menu");
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!gonggaolist?menu="+menu+"';</script>");
		
		
		
		
		
	}
	
//跳转到更新通知公告页面
	public String gonggaoupdate() {
		HttpServletRequest request = this.getRequest();
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		
		
		Gonggao bean = gonggaoDao.selectBean(" where id= "
				+ request.getParameter("id"));
		request.setAttribute("bean", bean);
		request.setAttribute("url", "method!gonggaoupdate2?id="+bean.getId()+"&menu="+menu);
		request.setAttribute("title", "通知公告修改");
		this.setUrl("admin/gonggao/gonggaoupdate.jsp");
		return SUCCESS;
	}
	
//更新通知公告操作
	public void gonggaoupdate2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();

		String gtitle = request.getParameter("gtitle");
		String gcontent = request.getParameter("gcontent");
		
		Gonggao bean = gonggaoDao.selectBean(" where id= "+ request.getParameter("id"));
		
		
		
		bean.setGtitle(gtitle);
		bean.setGcontent(gcontent);

		
		gonggaoDao.updateBean(bean);
		
		String menu = request.getParameter("menu");
		
		
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!gonggaolist?menu="+menu+"';</script>");
		
	}
	
	
//删除通知公告操作
	public void gonggaodelete() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		String menu = request.getParameter("menu");
		Gonggao bean = gonggaoDao.selectBean(" where id= "+ request.getParameter("id"));
		
		
		bean.setDeletestatus(1);
		gonggaoDao.updateBean(bean);
	
		
	
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!gonggaolist?menu="+menu+"';</script>");
	}
	
	//跳转到查看通知公告页面
	public String gonggaoupdate3() {
		HttpServletRequest request = this.getRequest();
		Gonggao bean = gonggaoDao.selectBean(" where id= "+ request.getParameter("id"));
		request.setAttribute("bean", bean);
		request.setAttribute("title", "通知公告查看");
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		this.setUrl("admin/gonggao/gonggaoupdate3.jsp");
		return SUCCESS;
	}

	@Autowired
	private ZhutiDao zhutiDao;

	public ZhutiDao getZhutiDao() {
		return zhutiDao;
	}

	public void setZhutiDao(ZhutiDao zhutiDao) {
		this.zhutiDao = zhutiDao;
	}
	
	
	//投票主题列表
	public String zhutilist() {
		HttpServletRequest request = this.getRequest();
		//控制左边菜单栏的展示或者闭合
		String menu = request.getParameter("menu");

		request.setAttribute("menu",menu );
		
		String ztitle = request.getParameter("ztitle");
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		
		if (ztitle != null && !"".equals(ztitle)) {

			sb.append("ztitle like '%" + ztitle + "%'");
			sb.append(" and ");
			request.setAttribute("ztitle", ztitle);
		}
		
		
		
		sb.append("   deletestatus=0   order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = zhutiDao.selectBeanCount(where.replaceAll("order by id desc", ""));
		request.setAttribute("list", zhutiDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!zhutilist?menu="+menu, "共有" + total + "条记录"));
		request.setAttribute("url", "method!zhutilist?menu="+menu);
		request.setAttribute("url2", "method!zhuti");
		request.setAttribute("title", "投票主题管理");
		this.setUrl("admin/zhuti/zhutilist.jsp");
		return SUCCESS;

	}
	
//跳转到添加投票主题页面
	public String zhutiadd() {
		HttpServletRequest request = this.getRequest();
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		
		
		request.setAttribute("url", "method!zhutiadd2?menu="+menu);
		request.setAttribute("title", "添加投票主题");
		this.setUrl("admin/zhuti/zhutiadd.jsp");
		return SUCCESS;
	}
	

	
	

	//添加投票主题操作
	public void zhutiadd2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		
		
		String ztitle = request.getParameter("ztitle");
		String shuoming = request.getParameter("shuoming");
		
		String stime = request.getParameter("stime");
		String etime = request.getParameter("etime");
		
		String menu = request.getParameter("menu");
				
		Zhuti bean =  new Zhuti();
		
		int s1 = Integer.parseInt(stime.replaceAll("-", ""));
		
		int e1 = Integer.parseInt(etime.replaceAll("-", ""));
		
		if(s1>=e1){
			writer.print("<script language=javascript>alert('操作失败，结束投票日期必须大于开始投票日期');window.location.href='method!zhutilist?menu="+menu+"';</script>");
			return;
		}
		
		
		bean.setCtime(Util.getRiqi());
		
		bean.setZtitle(ztitle);
		bean.setShuoming(shuoming);
		
		bean.setStime(stime);
		bean.setEtime(etime);
		
		
		zhutiDao.insertBean(bean);
		
		
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!zhutilist?menu="+menu+"';</script>");
		

		
	}
	
//跳转到更新投票主题页面
	public String zhutiupdate() {
		HttpServletRequest request = this.getRequest();
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		
		
		Zhuti bean = zhutiDao.selectBean(" where id= "
				+ request.getParameter("id"));
		request.setAttribute("bean", bean);
		request.setAttribute("url", "method!zhutiupdate2?id="+bean.getId()+"&menu="+menu);
		request.setAttribute("title", "投票主题修改");
		this.setUrl("admin/zhuti/zhutiupdate.jsp");
		return SUCCESS;
	}
	
//更新投票主题操作
	public void zhutiupdate2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();

		String ztitle = request.getParameter("ztitle");
		String shuoming = request.getParameter("shuoming");
		
		String stime = request.getParameter("stime");
		String etime = request.getParameter("etime");
		
		String menu = request.getParameter("menu");
		
		Zhuti bean = zhutiDao.selectBean(" where id= "+ request.getParameter("id"));
		
		int s1 = Integer.parseInt(stime.replaceAll("-", ""));
		
		int e1 = Integer.parseInt(etime.replaceAll("-", ""));
		
		if(s1>=e1){
			writer.print("<script language=javascript>alert('操作失败，结束投票日期必须大于开始投票日期');window.location.href='method!zhutilist?menu="+menu+"';</script>");
			return;
		}
		
		bean.setStime(stime);
		bean.setEtime(etime);
		
		bean.setZtitle(ztitle);
		bean.setShuoming(shuoming);

		
		zhutiDao.updateBean(bean);
		
		
		
		
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!zhutilist?menu="+menu+"';</script>");
		
	}
	
	
//删除投票主题操作
	public void zhutidelete() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		String menu = request.getParameter("menu");
		Zhuti bean = zhutiDao.selectBean(" where id= "+ request.getParameter("id"));
		
		
		bean.setDeletestatus(1);
		zhutiDao.updateBean(bean);
	
		
	
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!zhutilist?menu="+menu+"';</script>");
	}
	
	//跳转到查看投票主题页面
	public String zhutiupdate3() {
		HttpServletRequest request = this.getRequest();
		Zhuti bean = zhutiDao.selectBean(" where id= "+ request.getParameter("id"));
		request.setAttribute("bean", bean);
		request.setAttribute("title", "投票主题查看");
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		this.setUrl("admin/zhuti/zhutiupdate3.jsp");
		return SUCCESS;
	}

	@Autowired
	private RenDao renDao;

	public RenDao getRenDao() {
		return renDao;
	}

	public void setRenDao(RenDao renDao) {
		this.renDao = renDao;
	}
	
	
	
	//评选人员列表
	public String renlist() {
		HttpServletRequest request = this.getRequest();
		//控制左边菜单栏的展示或者闭合
		String menu = request.getParameter("menu");

		request.setAttribute("menu",menu );
		
		String zid = request.getParameter("zid");
		
		request.setAttribute("zid", zid);
		
		String xingming = request.getParameter("xingming");
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		
		if (xingming != null && !"".equals(xingming)) {

			sb.append("xingming like '%" + xingming + "%'");
			sb.append(" and ");
			request.setAttribute("xingming", xingming);
		}
		
		
		
		sb.append("   deletestatus=0  and zhuti.id="+zid+"  order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = renDao.selectBeanCount(where.replaceAll("order by id desc", ""));
		request.setAttribute("list", renDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!renlist?menu="+menu+"&zid="+zid, "共有" + total + "条记录"));
		request.setAttribute("url", "method!renlist?menu="+menu+"&zid="+zid);
		request.setAttribute("url2", "method!ren");
		request.setAttribute("title", "评选人员管理");
		this.setUrl("admin/ren/renlist.jsp");
		return SUCCESS;

	}
	
//跳转到添加评选人员页面
	public String renadd() {
		HttpServletRequest request = this.getRequest();
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		
		String zid = request.getParameter("zid");
		
		request.setAttribute("url", "method!renadd2?menu="+menu+"&zid="+zid);
		request.setAttribute("title", "添加评选人员");
		this.setUrl("admin/ren/renadd.jsp");
		return SUCCESS;
	}
	

	private File uploadfile;//

	public File getUploadfile() {
		return uploadfile;
	}

	public void setUploadfile(File uploadfile) {
		this.uploadfile = uploadfile;
	}
	

	//添加评选人员操作
	public void renadd2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		
		String zid = request.getParameter("zid");
		String haoci = request.getParameter("haoci");
		String xingming = request.getParameter("xingming");
		String keshi = request.getParameter("keshi");
		String shiji = request.getParameter("shiji");
				
		Ren bean =  new Ren();
		
		bean.setZhuti(zhutiDao.selectBean(" where id= "+zid));
		bean.setHaoci(haoci);

		bean.setXingming(xingming);
		
		bean.setKeshi(keshi);
		bean.setShiji(shiji);
		
		if(uploadfile!=null){
			String savapath = ServletActionContext.getServletContext().getRealPath("/")+"/uploadfile/";
			String time = Util.getTime2();
			String imgpath = time+".jpg";
			File file = new File(savapath+imgpath);
			Util.copyFile(uploadfile, file);
			bean.setPath(imgpath);
		}
		
		
		renDao.insertBean(bean);
		
		String menu = request.getParameter("menu");
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!renlist?menu="+menu+"&zid="+zid+"';</script>");
		
		
		
		
		
	}
	
//跳转到更新评选人员页面
	public String renupdate() {
		HttpServletRequest request = this.getRequest();
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		
		
		Ren bean = renDao.selectBean(" where id= "
				+ request.getParameter("id"));
		request.setAttribute("bean", bean);
		request.setAttribute("url", "method!renupdate2?id="+bean.getId()+"&menu="+menu);
		request.setAttribute("title", "评选人员修改");
		this.setUrl("admin/ren/renupdate.jsp");
		return SUCCESS;
	}
	
//更新评选人员操作
	public void renupdate2() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();

		String haoci = request.getParameter("haoci");
		String xingming = request.getParameter("xingming");
		String keshi = request.getParameter("keshi");
		String shiji = request.getParameter("shiji");
		
		
		Ren bean = renDao.selectBean(" where id= "+ request.getParameter("id"));
		
		
		bean.setHaoci(haoci);

		bean.setXingming(xingming);
		
		bean.setKeshi(keshi);
		bean.setShiji(shiji);
		
		if(uploadfile!=null){
			String savapath = ServletActionContext.getServletContext().getRealPath("/")+"/uploadfile/";
			String time = Util.getTime2();
			String imgpath = time+".jpg";
			File file = new File(savapath+imgpath);
			Util.copyFile(uploadfile, file);
			bean.setPath(imgpath);
		}

		
		renDao.updateBean(bean);
		
		String menu = request.getParameter("menu");
		
		
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!renlist?menu="+menu+"&zid="+bean.getZhuti().getId()+"';</script>");
		
	}
	
	
//删除评选人员操作
	public void rendelete() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		String menu = request.getParameter("menu");
		Ren bean = renDao.selectBean(" where id= "+ request.getParameter("id"));
		
		
		bean.setDeletestatus(1);
		renDao.updateBean(bean);
	
		
	
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!renlist?menu="+menu+"&zid="+bean.getZhuti().getId()+"';</script>");
	}
	
	//跳转到查看评选人员页面
	public String renupdate3() {
		HttpServletRequest request = this.getRequest();
		Ren bean = renDao.selectBean(" where id= "+ request.getParameter("id"));
		request.setAttribute("bean", bean);
		request.setAttribute("title", "评选人员查看");
		String menu = request.getParameter("menu");
		request.setAttribute("menu",menu );
		this.setUrl("admin/ren/renupdate3.jsp");
		return SUCCESS;
	}

	@Autowired
	private ToupiaoDao toupiaoDao;

	public ToupiaoDao getToupiaoDao() {
		return toupiaoDao;
	}

	public void setToupiaoDao(ToupiaoDao toupiaoDao) {
		this.toupiaoDao = toupiaoDao;
	}
	
	
	
	//投票记录列表
	public String toupiaolist() {
		HttpServletRequest request = this.getRequest();
		//控制左边菜单栏的展示或者闭合
		String menu = request.getParameter("menu");

		request.setAttribute("menu",menu );
		
		String ztitle = request.getParameter("ztitle");
		
		String xingming = request.getParameter("xingming");
		
		String username = request.getParameter("username");
		
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		
		if (ztitle != null && !"".equals(ztitle)) {

			sb.append(" ren.zhuti.ztitle like '%" + ztitle + "%'");
			sb.append(" and ");
			request.setAttribute("ztitle", ztitle);
		}
		
		if (xingming != null && !"".equals(xingming)) {

			sb.append(" ren.xingming like '%" + xingming + "%'");
			sb.append(" and ");
			request.setAttribute("xingming", xingming);
		}
		
		if (username != null && !"".equals(username)) {

			sb.append(" user.username like '%" + username + "%'");
			sb.append(" and ");
			request.setAttribute("username", username);
		}
		
		
		
		sb.append("   deletestatus=0   order by id desc ");
		String where = sb.toString();


		int curtoupiaotpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			curtoupiaotpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = toupiaoDao.selectBeanCount(where.replaceAll("order by id desc", ""));
		request.setAttribute("list", toupiaoDao.selectBeanList((curtoupiaotpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				curtoupiaotpage, "method!toupiaolist?menu="+menu, "共有" + total + "条记录"));
		request.setAttribute("url", "method!toupiaolist?menu="+menu);
		request.setAttribute("url2", "method!toupiao");
		request.setAttribute("title", "投票记录查询");
		this.setUrl("admin/toupiao/toupiaolist.jsp");
		return SUCCESS;

	}
	

	
	
	//投票主题列表
	public String zhutilist2() {
		HttpServletRequest request = this.getRequest();
		//控制左边菜单栏的展示或者闭合
		String menu = request.getParameter("menu");

		request.setAttribute("menu",menu );
		
		String ztitle = request.getParameter("ztitle");
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		
		if (ztitle != null && !"".equals(ztitle)) {

			sb.append("ztitle like '%" + ztitle + "%'");
			sb.append(" and ");
			request.setAttribute("ztitle", ztitle);
		}
		
		
		
		sb.append("   deletestatus=0   order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = zhutiDao.selectBeanCount(where.replaceAll("order by id desc", ""));
		request.setAttribute("list", zhutiDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!zhutilist2?menu="+menu, "共有" + total + "条记录"));
		request.setAttribute("url", "method!zhutilist2?menu="+menu);
		request.setAttribute("url2", "method!zhuti");
		request.setAttribute("title", "投票选项统计");
		this.setUrl("admin/zhuti/zhutilist2.jsp");
		return SUCCESS;

	}
	
	
	
	//评选人员列表
	public String renlist2() {
		HttpServletRequest request = this.getRequest();
		//控制左边菜单栏的展示或者闭合
		String menu = request.getParameter("menu");

		request.setAttribute("menu",menu );
		
		String zid = request.getParameter("zid");
		
		request.setAttribute("zid", zid);
		
		String xingming = request.getParameter("xingming");
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		
		if (xingming != null && !"".equals(xingming)) {

			sb.append("xingming like '%" + xingming + "%'");
			sb.append(" and ");
			request.setAttribute("xingming", xingming);
		}
		
		
		
		sb.append("   deletestatus=0  and zhuti.id="+zid+"  order by shu desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = renDao.selectBeanCount(where.replaceAll("order by shu desc", ""));
		request.setAttribute("list", renDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!renlist2?menu="+menu+"&zid="+zid, "共有" + total + "条记录"));
		request.setAttribute("url", "method!renlist2?menu="+menu+"&zid="+zid);
		request.setAttribute("url2", "method!ren");
		request.setAttribute("title", "统计详情");
		this.setUrl("admin/ren/renlist2.jsp");
		return SUCCESS;

	}
	
	
	//图表统计
	public String renlist3() throws IOException {
		HttpServletRequest request = this.getRequest();
		//控制左边菜单栏的展示或者闭合
		String menu = request.getParameter("menu");

		request.setAttribute("menu",menu );
		
		String zid = request.getParameter("zid");
		
		request.setAttribute("zid", zid);
		
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		
		
		
		sb.append("   deletestatus=0  and zhuti.id="+zid+"  order by shu desc ");
		String where = sb.toString();

		List<Ren> renlist = renDao.selectBeanList(0, 9999, where);
	

	
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();

		for(Ren bean:renlist){
			dataset.addValue(bean.getShu(), bean.getXingming(),bean.getXingming());
		}

	
		

		JFreeChart chart = ChartFactory.createBarChart3D(null, "候选人姓名",
				"票数", dataset, PlotOrientation.VERTICAL, true, false, false);

		//柱状图(CategoryPlot):   
		CategoryPlot plot = chart.getCategoryPlot();
		//获取图表区域对象   
		CategoryAxis domainAxis = plot.getDomainAxis();
		//水平底部列表    
		domainAxis.setLabelFont(new Font("黑体", Font.BOLD, 14));
		//水平底部标题    
		domainAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12));
		//垂直标题    
		ValueAxis rangeAxis = plot.getRangeAxis();
		//获取柱状    
		rangeAxis.setLabelFont(new Font("黑体", Font.BOLD, 15));
		chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15));

		String s = String.format("%d", new Date().getTime());
		request.setAttribute("time", s);

		String savaPath = ServletActionContext.getServletContext().getRealPath(
				"/")
				+ "/uploadfile/" + s + ".png";

		ChartUtilities.saveChartAsPNG(new File(savaPath), chart, 900, 430);
		

		request.setAttribute("title", "图表统计");
		
		this.setUrl("admin/ren/renlist3.jsp");
		
		return SUCCESS;

	}
	
	
	//用户列表
	public String userlist() {
		HttpServletRequest request = this.getRequest();
		//控制左边菜单栏的展示或者闭合
		String menu = request.getParameter("menu");

		request.setAttribute("menu",menu );
		
		String username = request.getParameter("username");
		
		StringBuffer sb = new StringBuffer();
		sb.append(" where ");

		
		if (username != null && !"".equals(username)) {

			sb.append("username like '%" + username + "%'");
			sb.append(" and ");
			request.setAttribute("username", username);
		}
		
		
		
		sb.append("   deletestatus=0  and role=1  order by id desc ");
		String where = sb.toString();


		int currentpage = 1;
		int pagesize = 10;
		if (request.getParameter("pagenum") != null) {
			currentpage = Integer.parseInt(request.getParameter("pagenum"));
		}
		int total = userDao.selectBeanCount(where.replaceAll("order by id desc", ""));
		request.setAttribute("list", userDao.selectBeanList((currentpage - 1)
				* pagesize, pagesize, where));
		request.setAttribute("pagerinfo", Pager.getPagerNormal(total, pagesize,
				currentpage, "method!userlist?menu="+menu, "共有" + total + "条记录"));
		request.setAttribute("url", "method!userlist?menu="+menu);
		request.setAttribute("url2", "method!user");
		request.setAttribute("title", "用户管理");
		this.setUrl("admin/user/userlist.jsp");
		return SUCCESS;

	}
	
	
	
//删除用户操作
	public void userdelete() throws IOException {
		HttpServletRequest request = this.getRequest();
		PrintWriter writer = this.getPrintWriter();
		String menu = request.getParameter("menu");
		User bean = userDao.selectBean(" where id= "+ request.getParameter("id"));
		
		
		bean.setDeletestatus(1);
		userDao.updateBean(bean);
	
		
	
		writer.print("<script language=javascript>alert('操作成功');window.location.href='method!userlist?menu="+menu+"';</script>");
	}
	
	
	
	
	
}
